<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<html>
<head>
    <title>登录页</title>
    <%--echart线图、柱状图、饼图等各种图型库 cdn--%>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/echarts/5.4.3/echarts.min.js"></script>
    <%--jquery cdn--%>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
</head>
<body>
职级<select name="levelId">
    <c:forEach items="${levelList}" var="l">
        <option value="${l.id}">${l.name}</option>
    </c:forEach>
</select><br>


职位描述  <input name="remark"><br>

<button onclick="zxt()">点击展示折线图</button>
<button onclick="zzt()">点击展示柱状图</button>
<button onclick="bing()">点击展示饼图</button>
<button onclick="excel()">点击导出Excel</button>

<div id="main" style="width: 500px;height: 500px">

</div>


</body>

<script>

    function bing() {

        let levelId = $('[name=levelId]').val();
        let remark = $('[name=remark]').val();

        $.ajax({
            url:'/bing.do?levelId='+levelId +'&remark=' + remark,
            success:function (res) {
                console.log(res)

                var chartDom = document.getElementById('main');
                var myChart = echarts.init(chartDom);
                var option;

                option = {
                    title: {
                        text: 'Referer of a Website',
                        subtext: 'Fake Data',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item'
                    },
                    legend: {
                        orient: 'vertical',
                        left: 'left'
                    },
                    series: [
                        {
                            name: 'Access From',
                            type: 'pie',
                            radius: '50%',
                            data: res,
                            emphasis: {
                                itemStyle: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                }
                            }
                        }
                    ]
                };

                option && myChart.setOption(option);
            }
        })


    }



    function zzt() {
        let levelId = $('[name=levelId]').val();
        let remark = $('[name=remark]').val();

        $.ajax({
            url:'/zxt.do?levelId='+levelId +'&remark=' + remark,
            success:function (res) {
                var x = []
                var y = []

                for (let i = 0; i < res.length; i++) {
                    x.push(res[i].xdata)
                    y.push(res[i].ydata)
                }

                var chartDom = document.getElementById('main');
                var myChart = echarts.init(chartDom);
                var option;

                option = {
                    xAxis: {
                        type: 'category',
                        data: x
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [
                        {
                            data: y,
                            type: 'bar',
                            showBackground: true,
                            backgroundStyle: {
                                color: 'rgba(180, 180, 180, 0.2)'
                            }
                        }
                    ]
                };

                option && myChart.setOption(option);

            }

        })
    }

    function excel() {
        let levelId = $('[name=levelId]').val();
        let remark = $('[name=remark]').val();
            location.href = '/excel.do?levelId='+levelId +'&remark=' + remark
    }

    function zxt() {

        let levelId = $('[name=levelId]').val();
        let remark = $('[name=remark]').val();

        $.get('/zxt.do?levelId='+levelId +'&remark=' + remark,function (res) {

            console.log(res)

            var x = []
            var y = []

            for (let i = 0; i < res.length; i++) {
                x.push(res[i].xdata)
                y.push(res[i].ydata)
            }

            var chartDom = document.getElementById('main');
            var myChart = echarts.init(chartDom);
            var option;

            option = {
                xAxis: {
                    type: 'category',
                    data: x
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        data: y,
                        type: 'line',
                        smooth: true
                    }
                ]
            };

            option && myChart.setOption(option);

        })

    }
</script>
</html>